<script type="text/javascript"> 
    var dojo;
    
    window.onload = function() {
        invalidLoginCheck();
        userAgentCheck();
        screenResCheck();
        var send = dojo.byId('send');
        send.onclick  = function () { pwdRecovery(); }; 
    }; 
    
    function invalidLoginCheck() {
        dojo.byId('login').innerHTML = 
            '<?php if($this->invalidLogin): ?>
                 <?php echo $this->translate('Invalid database, username or password') ?>
             <?php endif; ?>';
        
    }
    
    function userAgentCheck() {
        if('<?php echo $this->conf->browser->name ?>' !== '<?php echo $this->userAgent->getDevice()->getBrowser() ?>') {
            disableAll('<?php echo sprintf($this->translate('Invalid internet browser, %s required.'),
                $this->conf->browser->fullname) ?>');
        }
    }
    
    function screenResCheck() {
        if((window.screen.width < <?php echo $this->conf->screen->desktop->width; ?>)||
                (window.screen.height < <?php echo $this->conf->screen->desktop->height; ?>)) {
           disableAll('<?php echo sprintf($this->translate('Invalid screen resolution, required %s x %s pixels.'),
                $this->conf->screen->desktop->width,$this->conf->screen->desktop->height) ?>');
        }
    }
    
    function disableAll(message) {
        dojo.attr(dojo.byId('login'), 'class', 'err');
        dojo.byId('login').innerHTML = message;
        dojo.byId('db').disabled = true;
        dojo.byId('username').disabled = true;
        dojo.byId('password').disabled = true;
        dojo.byId('Submit').disabled = true;
        dojo.byId('email').disabled = true;
        dojo.byId('send').disabled = true;
    }
    
    function pwdRecovery() {
        var msg = dojo.byId('pwd-recovery-msg');
        
        var db = dojo.byId('db');
        if (!db.value) {
          dojo.attr(msg, 'class', 'err');
          msg.innerHTML = '<?php echo $this->translate('Set Database in the login form and try again') ?>';
          return;
        }
        
        var usr = dojo.byId('username');
        if (!usr.value) {
          dojo.attr(msg, 'class', 'err');
          msg.innerHTML = '<?php echo $this->translate('Enter Username in the login form and try again') ?>';
          return;
        }
        
        var email = dojo.byId('email');
        if (!email.value) {
          dojo.attr(msg, 'class', 'err');
          msg.innerHTML = '<?php echo $this->translate('Please enter your registered email below') ?>';
          return;
        }
        
        var cl = dojo.byId('cl');
        var locale = dojo.byId('locale');
        
        dojo.xhrGet({
            url: '/default/json/pwd-recovery/db/'+db.value+'/usr/'+usr.value+
                    '/email/'+email.value+'/cl/'+cl.value+'/locale/'+locale.value,
            handleAs: "json",
            timeout: 5000,
            load: function(response, ioArgs) {  
                dojo.attr(msg, 'class', response[0].oV);
                msg.innerHTML = response[0].oT;
                return response;
            },
            error: function(response, ioArgs) {
                dojo.attr(msg, 'class', 'err');
                msg.innerHTML = '<?php echo $this->translate('Please try sending again') ?>';
                return response;
            }
        });
    }
</script>

<table cellspacing="0">
    <tr>
        <td>
            <dl class="zend_form">
                <dt></dt>
                <dd><h3><?php echo $this->form->getAttrib('title') ?></h3></dd>
                <dt></dt>
                <dd><?php echo $this->form->getDescription() ?></dd>
                <dt></dt>
                <dd id="login" class="err"></dd>
            </dl>
            <?php echo $this->form ?>
        </td>
        <td class="separator"></td>
        <td style ="vertical-align: bottom;padding-left: 20px;">
            <div id="pwd_recovery">
                <h3><?php echo $this->formPwdRecovery->getAttrib('title') ?></h3>
                <div id="pwd-recovery-msg"><?php echo $this->formPwdRecovery->getDescription() ?></div>
                <?php echo $this->formPwdRecovery ?>
            </div>
        </td>
    </tr>
</table>